(ns lensfield.webapp.helpers
   (:import (java.io.File)))
   
(defn get-webapp-dir
   "Gets the path of the servlet context from the provided HTTPRequest."
   [req]
   (let [ctx (:servlet-context req)]
      (. ctx getRealPath "/")))

(defn find-index-file
   "Search the directory for index.*"
   [dir]
   (first
      (filter
         #(.startsWith (.toLowerCase (.getName %)) "index.")
         (.listFiles dir))))
            
(defn iterator-to-vector
   [iter]
   (loop [coll (vector)]
      (if (.hasNext iter)
         (recur (conj coll (.next iter)))
         coll)))